﻿using System;
using UnityEngine;
using UnityStandardAssets.Vehicles.Aeroplane;

// Token: 0x020003C4 RID: 964
public class VehicleEnterExit : MonoBehaviour
{
	// Token: 0x06001A70 RID: 6768 RVA: 0x000A5208 File Offset: 0x000A3408
	private void Awake()
	{
		this.vehicleInput = base.GetComponent<VehicleInputController>();
		this.aeroplaneControl = base.GetComponent<AeroplaneUserControl2Axis>();
		this.EnableControl(false);
		this.isOn = false;
		this.mainCamera = Camera.main;
		this.playerCamera = this.mainCamera.GetComponent<PlayerCamera>();
	}

	// Token: 0x06001A71 RID: 6769 RVA: 0x000A5258 File Offset: 0x000A3458
	private void Update()
	{
		if (base.transform.parent != null)
		{
			base.transform.SetParent(null);
		}
		if (base.transform.localScale.y != 1f)
		{
			base.transform.localScale = Vector3.one;
		}
		if (!this.justEntered && this.isOn && Input.GetButtonDown(ButtonInput.Enter))
		{
			this.isOn = false;
			this.GetPlayerOutsideOfVehicle();
			this.EnableControl(false);
		}
		if (this.isOn)
		{
			GameController.playerInstance.transform.position = base.transform.position;
		}
		if (this.justEntered)
		{
			this.justEntered = false;
		}
	}

	// Token: 0x06001A72 RID: 6770 RVA: 0x000A5324 File Offset: 0x000A3524
	public void EnterVehicle()
	{
		this.justEntered = true;
		this.isOn = true;
		GameController.playerInstance.SetActive(false);
		GameController.playerInstance.ChangeScale(1f);
		this.playerCamera.SetCameraTarget(base.transform);
		this.EnableControl(true);
	}

	// Token: 0x06001A73 RID: 6771 RVA: 0x000A5371 File Offset: 0x000A3571
	private void EnableControl(bool value)
	{
		if (this.vehicleInput)
		{
			this.vehicleInput.enabled = value;
		}
		if (this.aeroplaneControl)
		{
			this.aeroplaneControl.enabled = value;
		}
	}

	// Token: 0x06001A74 RID: 6772 RVA: 0x000A53AC File Offset: 0x000A35AC
	private void GetPlayerOutsideOfVehicle()
	{
		this.playerCamera.SetCameraTarget(GameController.playerInstance.transform);
		GameController.playerInstance.myTransform.position = base.transform.position - base.transform.right * 2f;
		GameController.playerInstance.SetActive(true);
	}

	// Token: 0x06001A75 RID: 6773 RVA: 0x000A540D File Offset: 0x000A360D
	private void OnDestroy()
	{
		if (this.isOn)
		{
			ObjectManager.Instance.vehicles.Remove(this);
			this.GetPlayerOutsideOfVehicle();
		}
	}

	// Token: 0x04001C3A RID: 7226
	private VehicleInputController vehicleInput;

	// Token: 0x04001C3B RID: 7227
	private AeroplaneUserControl2Axis aeroplaneControl;

	// Token: 0x04001C3C RID: 7228
	private Camera mainCamera;

	// Token: 0x04001C3D RID: 7229
	private PlayerCamera playerCamera;

	// Token: 0x04001C3E RID: 7230
	private bool isOn;

	// Token: 0x04001C3F RID: 7231
	private bool justEntered;
}
